import request from '@/services/request';
import { FormatDictData } from '@/utils/formatter';
import { TRAVEL_DEFAULT_URL } from './constants';

// 获取工作地列表
export const GetWorkplaceList = async () => {
  if (!TRAVEL_DEFAULT_URL) return;
  const res = await request(TRAVEL_DEFAULT_URL.workplaceList.url, {
    method: 'GET'
  });
  return FormatDictData(res.data, 'value', 'content');
};

// 获取系统时间
export const GetServerTime = async () => {
  if (!TRAVEL_DEFAULT_URL) return;
  const res = await request(TRAVEL_DEFAULT_URL.serverTime.url, {
    method: 'GET'
  });
  return res.data;
};

// 获取差旅计划
export const GetTravelPlanList = async (data: any) => {
  if (!TRAVEL_DEFAULT_URL) return;
  const res = await request(
    TRAVEL_DEFAULT_URL.travelPlanList.url +
    `?procName=${encodeURIComponent(data?.name)}`,
    {
      method: 'POST'
    }
  );
  if (!res.data) return;
  return FormatDictData(res.data, 'id', 'planName');
};

// 获取差旅计划详情
export const GetTravelPlanDetails = async (data: any) => {
  if (!TRAVEL_DEFAULT_URL) return;
  const res = await request(
    TRAVEL_DEFAULT_URL.travelPlanDetails.url + `?planId=${data?.id}`,
    {
      method: 'POST',
      data
    }
  );
  // res.data.list = FormatDictData(res.data.list, 'code', 'message');
  return res;
};
